package designPattern.singleton;

/**
 * lazy loading
 * 也称懒汉式
 * 有线程不安全问题
 */
public class singleton02 {
    private static singleton02 INSTANCE;

    private singleton02() {
    }

    public static singleton02 getInstance(){
        if (INSTANCE == null) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new singleton02();
        }
        return INSTANCE;
    }

    public void k(){
        System.out.println("OK");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread( ()-> System.out.println(singleton02.getInstance().hashCode())).start();
        }
    }


}
